home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / lwenvelope.lwm < prev    next >
Text File  |  1993-12-13  |  4KB  |  180 lines

  1. /* CMD: LW Envelope
  2.  * Make envelope file for LightWave 3D
  3.  * By Arnie Cachelin © 1992 NewTek Inc.
  4.  */
  5.  
  6. NUMERIC DIGITS 8
  7. call addlib "LWModelerARexx.port", 0
  8. call addlib "rexxsupport.library", 0, -30, 0
  9. signal on error
  10. signal on syntax
  11.  
  12. MATHLIB="rexxmathlib.library"
  13. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  14.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  15.     call notify(1,"!Can't find "MATHLIB)
  16.     exit
  17.     END
  18.  
  19. frames = 120
  20. fn = 1
  21. fun ="2*exp(-2*t)*(1+sin(5*t))"
  22. w = 5
  23. st = 2
  24. d=0
  25. KeySpacing =5
  26. sysnam = 'Envelope Maker '
  27. version = 'Envelope Maker 1.0'
  28. filnam = 'ENV:Envelope.state'
  29. if (exists(filnam)) then do
  30.     if (~open(state, filnam, 'R')) then break
  31.     if (readln(state) ~= version) then break
  32.     parse value readln(state) with frames fn w d st keyspacing .
  33.     fun = readln(state)
  34.     call close state
  35. end
  36.  
  37. FnList.1='RandomWalk'
  38. FnList.2='Oscillator'
  39. FnList.3='Bounce'
  40. FnList.4='Exponential'
  41. FnList.5='Custom'
  42. FList= FnList.1 FnList.2 FnList.3 FnList.4 FnList.5
  43.  
  44. call req_begin sysnam
  45.  
  46. id_mes  = req_addcontrol("Create LW",'T',"envelopes from mathematical functions")
  47. id_frames  = req_addcontrol("Frames", 'n')
  48. id_keysp  = req_addcontrol("Key Spacing", 'n')
  49. id_w  = req_addcontrol("Frequency", 'n')
  50. id_d  = req_addcontrol("Damping", 'n')
  51. id_st  = req_addcontrol("Start Value", 'n')
  52. id_fn  = req_addcontrol('Type:','CV',FList)
  53. id_fun = req_addcontrol("Custom f(t)", 's', 35)
  54.  
  55. call req_setval id_frames,frames
  56. call req_setval id_Keysp,keyspacing
  57. call req_setval id_fn, fn
  58. call req_setval id_w, w
  59. call req_setval id_d, d
  60. call req_setval id_st, st
  61. call req_setval id_fun, fun
  62.  
  63. if (~req_post()) then do
  64.     call req_end
  65.     exit
  66. end
  67.  
  68. /* Get input from Requester */
  69. frames   = req_getval(id_frames) % 1
  70. fn   = req_getval(id_fn)
  71. fun   = req_getval(id_fun)
  72. w   = req_getval(id_w)
  73. d   = req_getval(id_d)
  74. st   = req_getval(id_st)
  75. KeySpacing = req_getval(id_keysp)
  76.  
  77. call req_end
  78.  
  79. if (open(state, filnam, 'W')) then do
  80.     call writeln state, version
  81.     call writeln state, frames fn w d st keyspacing
  82.     call writeln state, fun
  83.     call close state
  84. end
  85.  
  86. ENVFile=getfilename("-- Save Envelope --","envelopes")
  87. if ENVFile ~="(none)" then File.Name=ENVFile
  88. else exit
  89.  
  90. h=0; p=0; b=0
  91. xsc=1; ysc=1; zsc=1
  92. File.type="LWEN"
  93. SecsPerFrame=1/30
  94. Time=SecsPerFrame*Frames
  95. Keys=1+Frames%KeySpacing
  96. SlicesPerFrame=1  /* No need for extra slices, since f'ns are analytic not evolved */
  97. dt=SecsPerFrame/SlicesPerFrame
  98. frame=0
  99. slice=0
  100.  
  101. /* Initial Conditions */
  102. v=st
  103. call meter_begin(frames*slicesperframe+5 , 'Generating Envelope',frames' Frames, 'Keys' Key Frames')
  104. call WriteHeader(mot,keys)
  105. do t=0 to Time+dt by dt
  106.     slice=slice+1
  107.     select
  108.       when fn=1 then v=RandomWalk(t)
  109.       when fn=2 then v=Oscillator(t,d)
  110.       when fn=3 then v=Bounce(t,d)
  111.       when fn=4 then v=Exponential(t)
  112.       when fn=5 then do
  113.         fnst="v="fun
  114.         interpret fnst
  115.         end
  116.       otherwise nop
  117.       end
  118.     if slice//SlicesPerFrame = 0 then do
  119.       if frame//KeySpacing=0 then
  120.         call WriteKey(mot,frame,0)
  121.       else if frame=Frames then
  122.         call WriteKey(mot,frame,0)
  123.       frame=frame+1
  124.     end
  125.     call meter_step()
  126. end
  127. call close mot
  128. call meter_end()
  129. call notify(1,'!Created LightWave Envelope File: 'File.name)
  130. exit
  131.  
  132. syntax:
  133. error:
  134.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  135.     exit
  136.  
  137. RandomWalk: procedure expose v w st
  138.   arg t
  139.   s=st*(2*randu()-1)
  140.   return(v+s)
  141.  
  142. Oscillator: procedure expose v w st
  143.   arg t,d
  144.   return( st*0.5*(1+exp(-d*t)*sin(w*t+90*st)) )
  145.  
  146. Bounce: procedure expose v w st
  147.   arg t,d
  148.   return( st*exp(-d*t)*abs(cos(w*t)) )
  149.  
  150. Exponential: procedure expose w st
  151.   arg t
  152.   return( st*exp(w*t) )
  153.  
  154. WriteKey:  PROCEDURE  EXPOSE v
  155.   arg MotFile, frame, lin
  156.   channels=v
  157.   spline=frame lin "0.0 0.0 0.0"
  158.   call writeln(MotFile,channels)
  159.   call writeln(MotFile,spline)
  160.   return frame
  161.  
  162. WriteHeader: PROCEDURE EXPOSE File.
  163.   arg MotFile, Keys
  164.   if open(MotFile,File.name,'W') then do
  165.     call writeln(MotFile,File.type)
  166.     call writeln(MotFile,"1") /* magic # */
  167.     call writeln(MotFile,"1") /* Channels */
  168.     call writeln(MotFile,Keys)
  169.   end
  170.   else do
  171.     Bummer("Can't open Envelope file : "File.name)
  172.   end
  173.   return 1
  174.  
  175. Bummer:
  176.  ARG etxt
  177.  SAY "ERROR: "||RC||etxt
  178.  call end_all
  179.  exit
  180.